<?php

/**
 * This is the model class for table "team".
 *
 * The followings are the available columns in table 'team':
 * @property integer $idteam
 * @property string $short_name
 * @property string $full_name
 * @property string $enabled
 * @property string $description
 * @property string $email_distribution
 * @property string $pad_url
 *
 * The followings are the available model relations:
 * @property ActivityLog[] $activityLogs
 * @property Callback[] $callbacks
 * @property Links[] $links
 * @property Notifications[] $notifications
 * @property Qshift[] $qshifts
 * @property QshiftChange[] $qshiftChanges
 * @property Role[] $roles
 * @property Schedule[] $schedules
 * @property Shift[] $shifts
 * @property ShiftChange[] $shiftChanges
 * @property User[] $users
 */
class Team extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Team the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'team';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('short_name', 'length', 'max'=>10),
			array('full_name, email_distribution', 'length', 'max'=>45),
			array('enabled', 'length', 'max'=>1),
			array('description, pad_url', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idteam, short_name, full_name, enabled, description, email_distribution, pad_url', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'activityLogs' => array(self::HAS_MANY, 'ActivityLog', 'team_id'),
			'callbacks' => array(self::HAS_MANY, 'Callback', 'team_id'),
			'links' => array(self::HAS_MANY, 'Links', 'team_id'),
			'notifications' => array(self::HAS_MANY, 'Notifications', 'team_id'),
			'qshifts' => array(self::HAS_MANY, 'Qshift', 'team_id'),
			'qshiftChanges' => array(self::HAS_MANY, 'QshiftChange', 'team_id'),
			'roles' => array(self::HAS_MANY, 'Role', 'team_id'),
			'schedules' => array(self::HAS_MANY, 'Schedule', 'team_id'),
			'shifts' => array(self::HAS_MANY, 'Shift', 'team_id'),
			'shiftChanges' => array(self::HAS_MANY, 'ShiftChange', 'team_id'),
			'users' => array(self::HAS_MANY, 'User', 'team'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idteam' => 'Idteam',
			'short_name' => 'Short Name',
			'full_name' => 'Full Name',
			'enabled' => 'Enabled',
			'description' => 'Description',
			'email_distribution' => 'Email Distribution',
			'pad_url' => 'Etherpad URL',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idteam',$this->idteam);
		$criteria->compare('short_name',$this->short_name,true);
		$criteria->compare('full_name',$this->full_name,true);
		$criteria->compare('enabled',$this->enabled,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('email_distribution',$this->email_distribution,true);
		$criteria->compare('pad_url',$this->pad_url,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}